//
//  TWFXWeatherCell.m
//
//
//  Created by Lion User on 13-10-7.
//  Copyright (c) 2013年 Lion User. All rights reserved.
//

#import "TWFXWeatherCell.h"

@implementation TWFXWeatherCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _beforeStateIsDelete = NO;
        
        self.labelCityName = [[[UILabel alloc] initWithFrame:CGRectMake(70, 0, 250, 40)] autorelease];
        self.labelCityWeather = [[[UILabel alloc] initWithFrame:CGRectMake(70, 35, 250, 20)] autorelease];
        
        //清除UIlabel的背景颜色,不能直接设为nil
        self.labelCityName.BackgroundColor = [UIColor clearColor];
        self.labelCityWeather.BackgroundColor = [UIColor clearColor];
        
        self.labelCityName.font = [UIFont systemFontOfSize:20.0f];
        self.labelCityWeather.font = [UIFont systemFontOfSize:14.0f];
        
        self.image_weather = [[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 50, 50)]autorelease];
        
        [self.contentView addSubview:self.labelCityName];
        [self.contentView addSubview:self.labelCityWeather];
        [self.contentView addSubview:self.image_weather];
        
    }
    return self;
}



/*
 CustomTableViewCell为UITableViewCell的子类，在实现文件中重写willTransitionToState方法。
 willTransitionToState是在cell改变显示状态的时候调用，有三种状态：
 typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {
 UITableViewCellStateDefaultMask = 0, //普通状态
 UITableViewCellStateShowingEditControlMask = 1 << 0, //编辑状态
 UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1 //删除状态
 };
 */

-(void)willTransitionToState:(UITableViewCellStateMask)state
{
    [super willTransitionToState:state];
    
    //一般状态
    if (state == UITableViewCellStateDefaultMask) {
        
        self.labelCityName.frame = CGRectMake(70, 0, 250, 40);
        self.labelCityWeather.frame = CGRectMake(70, 35, 250, 20);
        
        if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
        {
            self.image_weather.frame = CGRectMake(10, 5, 50, 50);
        }
    }
    //编辑状态,删除状态 增加状态 移动状态都属于编辑状态
    else if(state == UITableViewCellStateShowingEditControlMask)
    {
        self.labelCityName.frame = CGRectMake(70, 0, 200, 40);
        self.labelCityWeather.frame = CGRectMake(70, 35, 200, 20);
    }
    //删除状态,点击左边的红色的减号时 右边的delete按钮出现前
    else if (state == 3) {
        
        self.labelCityName.frame = CGRectMake(70, 0, 170, 40);
        self.labelCityWeather.frame = CGRectMake(70, 35, 170, 20);
        
    }
    //左右滑动cell时,cell的右边也会出现删除按钮,这时state的值是 UITableViewCellStateShowingDeleteConfirmationMask
    else if (state == UITableViewCellStateShowingDeleteConfirmationMask)
    {
        //IOS7时，右边出现delete按钮时，是把左边的控件往左边推
        if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
        {
            self.image_weather.frame = CGRectMake(80, 5, 50, 50);
            self.labelCityName.frame = CGRectMake(140, 0, 170, 40);
            self.labelCityWeather.frame = CGRectMake(140, 35, 170, 20);
        }
        //IOS6及之前，右边出现delete按钮时，是覆盖左边的控件
        else
        {
            self.labelCityName.frame = CGRectMake(70, 0, 170, 40);
            self.labelCityWeather.frame = CGRectMake(70, 35, 170, 20);
        }
        
    }
    
}

-(void)didTransitionToState:(UITableViewCellStateMask)state
{
    [super didTransitionToState:state];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [_labelCityName release];
    [_labelCityWeather release];
    [_labelUpdateTime release];
    [_image_weather release];
    [super dealloc];
}

@end
